Configure the Visual Basic 6.0 Project
Open the Visual Basic 6 project that needs to interact with the new .NET InteropForms or Interop UserControls.
A reference to the InteropFormTools library needs to be added to the Visual Basic 6.0 project. Likewise, a reference to the custom assembly that contains the .NET Form to launch from Visual Basic 6.0 is also needed. To do this, click Project | References. Then find and check "Microsoft Interop Forms Toolkit Library" along with any custom assemblies.
The .NET Forms created as part of the Visual Basic 6.0 application do not know to close themselves when the Visual Basic 6.0 application shuts down. This is noticeable when debugging in the Visual Basic 6.0 IDE, because the "Visual Basic 6.0.exe" process is still running. To improve the debugging experience and to properly clean up .NET Forms created from within a Visual Basic 6.0 application, the InteropToolbox manages all of the .NET Forms. The Visual Basic 6.0 application simply needs to notify the InteropToolbox when the application is starting up and shutting down in order to cleanly dispose of the Forms. The following code shows the pattern that should be followed to properly implement the InteropToolbox functionality.
Declare a global instance of the toolbox:
Public g_InteropToolbox As InteropToolbox
Instantiate the toolbox, call Initialize on it for debugging support, and then signal the start of the application when the application starts (Sub Main or Main Form Load):
Set g_InteropToolbox = New InteropToolbox
' This aids in the debugging experience
g_InteropToolbox.Initialize
g_InteropToolbox.EventMessenger.RaiseApplicationStartedupEvent
Signal the shutdown of the application when the application ends (Sub Main or Main Form QueryUnload):
g_InteropToolbox.EventMessenger.RaiseApplicationShutdownEvent